home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Resources
/
Chat & Communication
/
Digsby build 37
/
digsby_setup.exe
/
lib
/
prefs
/
prefsdata.pyo
(
.txt
)
< prev
next >
Wrap
Python Compiled Bytecode
|
2008-10-13
|
5KB
|
167 lines
# Source Generated with Decompyle++
# File: in.pyo (Python 2.5)
import os
import util
from util import dictadd, is_all
from util.observe import observable_dict
import syck
from logging import getLogger
log = getLogger('PrefsData')
info = log.info
warning = log.warning
def flatten(mapping, parent_name = ''):
if not mapping:
return []
result_list = []
for key, value in mapping.iteritems():
path = parent_name + key
if isinstance(value, dict) or hasattr(key, 'iteritems'):
result_list.extend(flatten(value, path + '.'))
continue
result_list.append((path, value))
return result_list
def inflate(mappings_list, root = None, dict_factory = dict):
if not root:
pass
root_map = dict_factory()
for path, value in mappings_list:
path = path.split('.')
parent = root_map
for name in path:
if path[-1] == name:
parent[name] = value
else:
parent.setdefault(name, dict_factory())
parent = parent[name]
return root_map
nice_type_names = {
unicode: 'unicode',
str: 'str',
bool: 'boolean',
int: 'integer',
list: 'list',
float: 'float',
dict: 'dict',
type(None): 'none' }
from util import dictreverse
nice_name_types = dictreverse(nice_type_names)
__localprefs = None
class localprefprop(object):
def __init__(self, key, default):
if isinstance(key, basestring):
key = lambda s: key
self.key = key
self.default = default
def __get__(self, obj, objtype = None):
try:
return localprefs()[self.key(obj)]
except KeyError:
return self.default
def __set__(self, obj, val):
localprefs()[self.key(obj)] = val
def defaultprefs():
flatten = flatten
import prefs
resdir = os.path.join(util.program_dir(), 'res')
filename = os.path.join(resdir, 'defaults.yaml')
info('loading default prefs from %s', filename)
prefs_path = filename
fc = util.filecontents(prefs_path)
defaults = util.Storage(flatten(syck.load(fc)))
platformName = platformName
import config
filename = os.path.join(resdir, platformName, 'defaults.yaml')
if os.path.exists(filename):
info('loading default platform prefs from %s', filename)
prefs_path = filename
fc = util.filecontents(prefs_path)
platprefs = util.Storage(flatten(syck.load(fc)))
defaults.update(platprefs)
return defaults
def localprefs():
global __localprefs
import common
if __localprefs is not None and __localprefs.name == common.profile.name:
return __localprefs
local_settings = local_settings
import gui.toolbox
SavingDictBase = ObservableDict
import util.observe
ls = local_settings()
_section = lambda : 'localprefs %s' % common.profile.name
section = _section()
if not ls.has_section(section):
ls.add_section(section)
class SavingDict('SavingDict', (SavingDictBase,)):
import localdefaults
name = common.profile.name
def __init__(self, save_func, *a, **k):
self.save = save_func
SavingDictBase.__init__(self, *a, **k)
def __setitem__(self, key, val):
SavingDictBase.__setitem__(self, key, val)
self.save(self)
def __delitem__(self, key):
SavingDictBase.__delitem__(self, key)
self.save(self)
def __getitem__(self, key):
try:
return SavingDictBase.__getitem__(self, key)
except KeyError:
e = None
try:
v = getattr(self.localdefaults, key.replace('.', '_'))
except AttributeError:
raise e
return None if callable(v) else v
def save(d):
ls._sections[_section()] = d.copy()
ls.save()
__localprefs = SavingDict(save, ls.iteritems(section))
return __localprefs